package com.zr.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.model.User;
import com.zr.service.UserService;

import net.sf.json.JSONObject;
/**
 * 用户信息添加的servlet
 * @author Administrator
 *
 */
public class AddUserController extends HttpServlet{
	//实例化对应的服务层
	UserService userservice = new UserService();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	// TODO Auto-generated method stub
	doPost(req, resp);
}
@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
	//接受页面传过来的值
    String adduser = req.getParameter("user");
    //将取到的字符串转换成json对象
    JSONObject json = JSONObject.fromObject(adduser);
    //将json对象转换为java对象
    User user = (User)JSONObject.toBean(json,User.class);
    boolean flag = userservice.addUserAdmins(user);
    //拿到这只笔
    PrintWriter pw = resp.getWriter();
    //把结果写回去
    pw.write(flag+"");
	}
}
